package com.os.opencv.java.chapter4;

import org.opencv.core.*;
import org.opencv.highgui.HighGui;
import org.opencv.imgcodecs.Imgcodecs;

public class BitwiseXor {

    public static void main(String[] args) {
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

        //读取图像文件并在屏幕上显示
        Mat src = Imgcodecs.imread("/Users/matt/MATT-MAC/matt_workspace/OS-OpenCV_workspace/view.jpg");
        HighGui.imshow("src", src);
        HighGui.waitKey(0);

        //读取秘钥图像并在屏幕上显示，创建一个窗口图像，北京维全黑色，中央区域有一个白色实心矩形
        Mat key = Imgcodecs.imread("/Users/matt/MATT-MAC/matt_workspace/OS-OpenCV_workspace/view.jpg");
        HighGui.imshow("key", key);
        HighGui.waitKey(0);

        //按位异或加密提箱并在屏幕上显示
        Mat dst = new Mat();
        Core.bitwise_xor(src, key, dst);
        HighGui.imshow("encrypted", dst);
        HighGui.waitKey(0);

        //再次执行按位异或操作解密图像并在屏幕上显示
        Core.bitwise_xor(dst, key, dst);
        HighGui.imshow("decrypted", dst);
        HighGui.waitKey(0);

        System.exit(0);
    }
}
